Skip to content

Conversation

@paoloricciuti
Copy link
Member

Closes #16997

Just an experiment...the comment was proposing overloading context but I think that would be bad for two reasons:

  1. it's an overload which is never nice
  2. You can technically do stuff that is not just setting context in this function (I don't know if you should but you can)

This could also have some interesting side effects like being able to register an effect that is in context of the component but outside of it...dunno maybe could be useful for testing.

Didn't add a test because we don't have test for mount...but...should we?

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link

changeset-bot bot commented Jan 22, 2026

🦋 Changeset detected

Latest commit: 642f967

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@17515

@andyearnshaw
Copy link

It's great that you put something together so quickly!

You can technically do stuff that is not just setting context in this function (I don't know if you should but you can)

This was the main reason I suggested a function alternative for context instead, as I wasn't sure about the consequences of allowing component side effects.

@paoloricciuti
Copy link
Member Author

This was the main reason I suggested a function alternative for context instead, as I wasn't sure about the consequences of allowing component side effects.

This is just another name...you could've declared an effect also inside your context function, just with less clarity.

@svelte-docs-bot
Copy link

@paoloricciuti
Copy link
Member Author

However I just realized a problem...effects declared in here don't get triggered which could leak memory...investigating

@paoloricciuti
Copy link
Member Author

Fixed it

@Rich-Harris
Copy link
Member

Alternatively, we could solve this without adding any new API at all: #16997 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable usage of createContext with independent mount

3 participants